import Vue from "vue"
import Router from "vue-router"
/* Layout */
import Layout from "@/views/layout/Layout"
import CashierLayout from "@/views/cashier/layout"

Vue.use(Router)

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    perms: ['GET /aaa','POST /bbb']     will control the page perms (you can set multiple perms)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
 **/
export const constantRouterMap = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path*",
        component: () => import("@/views/redirect/index")
      }
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    name: "merchantReg",
    path: "/merchantReg",
    component: () => import("@/views/merchantReg/merchantReg"),
    hidden: true
  },
  {
    name: "merchantRegSuc",
    path: "/merchantRegSuc",
    component: () => import("@/views/merchantReg/merchantRegSuc"),
    hidden: true
  },
  {
    path: "/auth-redirect",
    component: () => import("@/views/login/authredirect"),
    hidden: true
  },
  {
    path: "/404",
    component: () => import("@/views/errorPage/404"),
    hidden: true
  },
  {
    path: "/401",
    component: () => import("@/views/errorPage/401"),
    hidden: true
  },
  {
    path: "",
    component: Layout,
    redirect: "dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index"),
        name: "Dashboard",
        meta: { title: "首页", icon: "dashboard", noCache: true }
      }
    ]
  },
  {
    name: "brandInfo",
    path: "/brandInfo",
    component: () => import("@/views/brandInfo/brandInfo"),
    hidden: true
  },
  {
    path: "/cashier",
    name: "cashier",
    component: CashierLayout,
    hidden: false,
    meta: {
      title: "收银台管理",
      menuId: 62,
      icon: "nested",
      noCache: true
    },
    children: [
      {
        path: "home",
        component: () => import("@/views/cashier/home"),
        name: "home",
        meta: {
          title: "收银台",
          icon: "nested",
          menuId: 63,
          noCache: true
        },
        hidden: false
      },
      {
        path: "order",
        component: () => import("@/views/cashier/order"),
        name: "order",
        meta: {
          title: "订单管理",
          icon: "nested",
          menuId: 64,
          noCache: true
        },
        hidden: true
      },
      {
        path: "member",
        component: () => import("@/views/cashier/member"),
        name: "member",
        meta: {
          title: "会员管理",
          icon: "user",
          menuId: 65,
          noCache: true
        },
        hidden: true
      },
      {
        path: "transmitOrder",
        component: () => import("@/views/cashier/transmitOrder"),
        name: "transmitOrder",
        meta: {
          title: "接单管理",
          menuId: 66,
          icon: "user",
          noCache: true
        },
        hidden: true
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: "/mall",
    component: Layout,
    redirect: "noredirect",
    alwaysShow: true,
    name: "mallManage",
    meta: {
      title: "进销存管理",
      menuId: 1,
      icon: "shopping"
    },
    children: [
      {
        path: "list",
        component: () => import("@/views/mall/list"),
        name: "goodsList",
        meta: {
          perms: ["GET /merchant/goods/list", "POST /merchant/goods/delete"],
          title: "商品库",
          icon: "list",
          menuId: 2,
          noCache: true
        }
      },
      {
        path: "create",
        component: () => import("@/views/mall/create"),
        name: "goodsCreate",
        meta: {
          perms: ["POST /merchant/goods/create"],
          title: "添加商品",
          icon: "link",
          menuId: 3,
          noCache: true
        },
        hidden: true
      },
      {
        path: "edit",
        component: () => import("@/views/mall/edit"),
        name: "goodsEdit",
        meta: {
          perms: [
            "GET /merchant/goods/detail",
            "POST /merchant/goods/update",
            "POST /merchant/goods/catAndBrand"
          ],
          title: "商品编辑",
          icon: "form",
          menuId: 4,
          noCache: true
        },
        hidden: true
      },
      {
        path: "beginningInventory",
        component: () => import("@/views/mall/beginningInventory"),
        name: "beginningInventory",
        meta: {
          perms: [],
          title: "库存查询",
          icon: "form",
          menuId: 5,
          noCache: true
        },
        hidden: false
      },
      {
        path: "inventoryPurchase",
        component: () => import("@/views/mall/inventoryPurchase"),
        name: "inventoryPurchase",
        meta: {
          perms: [],
          title: "库存进货",
          icon: "form",
          menuId: 6,
          noCache: true
        },
        hidden: false
      },
      {
        path: "inventoryManagement",
        component: () => import("@/views/mall/inventory"),
        name: "inventoryManagement",
        meta: {
          perms: [],
          title: "存货查询",
          icon: "form",
          menuId: 7,
          noCache: true
        },
        hidden: false
      },
      {
        path: "order",
        component: () => import("@/views/mall/order"),
        name: "order",
        meta: {
          perms: [
            "*"
          ],
          title: "订单管理",
          icon: "nested",
          menuId: 8,
          noCache: true
        }
      },
      {
        path: "transmitOrder",
        component: () => import("@/views/mall/transmitOrder"),
        name: "transmitOrder",
        meta: {
          perms: [
            "*"
          ],
          title: "接单管理",
          icon: "nested",
          menuId: 9,
          noCache: true
        }
      },
      {
        path: "financialManagement",
        component: () => import("@/views/stat/accountstatist2"),
        name: "financialManagement",
        meta: {
          perms: [
            "*"
          ],
          title: "销售统计",
          icon: "nested",
          menuId: 10,
          noCache: true
        }
      },
      {
        path: "withdrawalrecord",
        component: () => import("@/views/stat/withdrawalrecord"),
        name: "withdrawalrecord",
        meta: {
          perms: ["*"],
          title: "提账记录",
          icon: "shopping",
          menuId: 11,
          noCache: true
        }
      }
    ]
  },
  {
    path: "/user",
    component: Layout,
    redirect: "noredirect",
    alwaysShow: true,
    name: "userManage",
    meta: {
      title: "会员管理",
      menuId: 12,
      icon: "peoples"
    },
    children: [
      {
        path: "user",
        component: () => import("@/views/user/user"),
        name: "user",
        meta: {
          perms: ["*"],
          title: "会员列表",
          icon: "user",
          menuId: 13,
          noCache: true
        }
      }
    ]
  },
  {
    path: "/promotion",
    component: Layout,
    redirect: "noredirect",
    alwaysShow: true,
    name: "promotionManage",
    meta: {
      title: "活动管理",
      menuId: 14,
      icon: "size"
    },
    children: [
      {
        path: "reduce",
        component: () => import("@/views/promotion/discountGift"),
        props: (route) => ({ disCountType: 1 }), // 将动态段的值作为prop传递给组
        name: "reduce",
        meta: {
          perms: [
            "*"
          ],
          title: "满减活动",
          icon: "reduce",
          menuId: 15,
          noCache: true
        }
      },
      {
        path: "discount",
        component: () => import("@/views/promotion/discountGift"),
        props: (route) => ({ disCountType: 2 }), // 将动态段的值作为prop传递给组
        name: "discount",
        meta: {
          perms: [
            "*"
          ],
          title: "拆扣活动",
          icon: "discount",
          menuId: 16,
          noCache: true
        }
      },
      {
        path: "special",
        component: () => import("@/views/promotion/discountGift"),
        props: (route) => ({ disCountType: 3 }), // 将动态段的值作为prop传递给组
        name: "special",
        meta: {
          perms: [
            "*"
          ],
          title: "特价活动",
          icon: "special",
          menuId: 17,
          noCache: true
        }
      },
      {
        path: "gift",
        component: () => import("@/views/promotion/discountGift"),
        props: (route) => ({ disCountType: 4 }), // 将动态段的值作为prop传递给组
        name: "gift",
        meta: {
          perms: [
            "*"
          ],
          title: "赠品活动",
          icon: "gift",
          menuId: 18,
          noCache: true
        }
      }
    ]
  },
  {
    path: "/sys",
    component: Layout,
    redirect: "noredirect",
    alwaysShow: true,
    name: "sysManage",
    meta: {
      title: "系统管理",
      menuId: 19,
      icon: "component"
    },
    children: [
      {
        path: "admin",
        component: () => import("@/views/sys/admin"),
        name: "admin",
        meta: {
          perms: [
            "*"
          ],
          title: "管理员",
          menuId: 20,
          icon: "people",
          noCache: true
        }
      },
      {
        path: "role",
        component: () => import("@/views/sys/role"),
        name: "role",
        meta: {
          perms: [
            "*"
          ],
          title: "角色管理",
          icon: "qq",
          menuId: 21,
          noCache: true
        }
      }
    ]
  },

  {
    path: "/stat",
    component: Layout,
    redirect: "noredirect",
    alwaysShow: true,
    name: "statManage",
    meta: {
      title: "对账管理",
      icon: "chart"
    },
    hidden: true,
    children: [
      {
        path: "accountstatist",
        component: () => import("@/views/stat/accountstatist"),
        name: "accountStatist",
        meta: {
          perms: ["GET /merchant/bill/list"],
          title: "对账统计",
          icon: "user",
          noCache: true
        },
        hidden: true
      },
      {
        path: "withdrawalrecord",
        component: () => import("@/views/stat/withdrawalrecord"),
        name: "withdrawalrecord",
        meta: {
          perms: ["GET /merchant/bill/overview"],
          title: "提账记录",
          icon: "shopping",
          noCache: true
        },
        hidden: true
      }
    ]
  },
  {
    path: "/profile",
    component: Layout,
    redirect: "noredirect",
    alwaysShow: true,
    children: [
      {
        path: "password",
        component: () => import("@/views/profile/password"),
        name: "password",
        meta: { title: "修改密码", noCache: true }
      }
    ],
    hidden: true
  },

  { path: "*", redirect: "/404", hidden: true }
]
